package com.logic.presenter

import com.logic.contract.StockOutRfidContract
import com.sinopec.basemodule.api.BaseModuleApi
import com.sinopec.basemodule.http.CommonObserver
import com.sinopec.basemodule.http.ExceptionEngine
import com.sinopec.basemodule.model.ErrorPalletCodeResultModel
import com.sinopec.basemodule.model.StockOutApiRequestModel

/**
 * @author lwj
 * @ClassName: StockInRfidPresenter
 * @Description: 出库-rfid扫码界面
 */
class StockOutRfidPresenter(view: StockOutRfidContract.View) :
    StockOutRfidContract.Presenter(view) {

    /**
     * 确认出库-编码校验
     */
    override fun confirmStockOut(model: StockOutApiRequestModel) {
        val resultObservable = BaseModuleApi.confirmStockOut(model)
        toSubscribe(resultObservable, object : CommonObserver<List<ErrorPalletCodeResultModel>>(mView.context) {
                override fun onNext(errorList: List<ErrorPalletCodeResultModel>) {
                    mView.confirmStockOutSuccess(model.palletCodes, getData())
                }

                override fun onError(t: ExceptionEngine.ResponseThrowable) {
                    mView.confirmStockOutSuccess(model.palletCodes, getData())
                    mView.showMessage(t.message)
                }
            })
    }

    /**
     * 测试数据
     */
    private fun getData(): List<ErrorPalletCodeResultModel> {
        val list: MutableList<ErrorPalletCodeResultModel> = ArrayList()
        val model1 = ErrorPalletCodeResultModel("86 10 81 42 B0 5A","物料不匹配，请查看具体原因，如有不清楚请联系管理员！")
        val model2 = ErrorPalletCodeResultModel("86 10 81 42 B0 5B","编码未入库")
        list.add(model1)
        list.add(model2)
        return list
    }
}